package com.sample.generator.util;

import java.io.IOException;
import java.io.InputStream;

public class ClassUtil {

	private ClassUtil() {
	}

	private static ClassLoader getClassLoader() {

		ClassLoader classLoader = Thread.currentThread()
				.getContextClassLoader();
		if (classLoader == null) {
			return GeneratorUtil.class.getClassLoader();
		} else {
			return classLoader;
		}
	}

	public static InputStream getResourceAsStream(String name)
			throws IOException {

		if (name == null) {
			throw new IllegalArgumentException("Argument name is null.");
		}
		InputStream is = getClassLoader().getResourceAsStream(name);
		if (is == null) {
			throw new IOException("Resource '" + name + "' is not found.");
		} else {
			return is;
		}
	}
}
